package com.ruoyi.project.inventory.service.impl;

import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.project.tool.gen.util.FirstLetterPingYin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.project.inventory.mapper.RyInventoryMapper;
import com.ruoyi.project.inventory.domain.RyInventory;
import com.ruoyi.project.inventory.service.IRyInventoryService;

/**
 * 物品信息Service业务层处理
 *
 * @author you
 * @date 2022-09-05
 */
@Service
public class RyInventoryServiceImpl implements IRyInventoryService
{
    @Autowired
    private RyInventoryMapper ryInventoryMapper;


    public List<RyInventory> all(){
        return ryInventoryMapper.all();
    }
    /**
     * 查询物品信息
     *
     * @param id 物品信息主键
     * @return 物品信息
     */
    @Override
    public RyInventory selectRyInventoryById(Long id)
    {
        return ryInventoryMapper.selectRyInventoryById(id);
    }

    /**
     * 查询物品信息列表
     *
     * @param ryInventory 物品信息
     * @return 物品信息
     */
    @Override
    public List<RyInventory> selectRyInventoryList(RyInventory ryInventory)
    {
        return ryInventoryMapper.selectRyInventoryList(ryInventory);
    }

    /**
     * 根据规格查询商品信息
     */
    @Override
    public RyInventory selectRyInventorySpeciInFor(String specifications) {
        return ryInventoryMapper.selectRyInventorySpeciInFor(specifications.replaceAll(" ","").toUpperCase());
    }

    /**
     * 根据商品名称和规格查询商品信息
     * 这里的商品名称和规格应该是去空格并且全大写后的参数
     */
    public RyInventory selectInfoByNameSpeci(String specifications,String name){
        return ryInventoryMapper.selectInfoByNameSpeci(specifications.replaceAll(" ","").toUpperCase(),name.replaceAll(" ","").toUpperCase());
    }

    /**
     * 新增物品信息
     *
     * @param ryInventory 物品信息
     * @return 结果
     */
    @Override
    public int insertRyInventory(RyInventory ryInventory)
    {
        ryInventory.setCreateTime(DateUtils.getNowDate());
        ryInventory.setName(ryInventory.getName().replaceAll(" ",""));
        ryInventory.setSpecifications(ryInventory.getSpecifications().replaceAll(" ",""));
        ryInventory.setFirstLetter(FirstLetterPingYin.FirstLetter(ryInventory.getName()));
        return ryInventoryMapper.insertRyInventory(ryInventory);
    }

    /**
     * 修改物品信息
     *
     * @param ryInventory 物品信息
     * @return 结果
     */
    @Override
    public int updateRyInventory(RyInventory ryInventory)
    {
        ryInventory.setUpdateTime(DateUtils.getNowDate());
        ryInventory.setName(ryInventory.getName().replaceAll(" ",""));
        ryInventory.setSpecifications(ryInventory.getSpecifications().replaceAll(" ",""));
        ryInventory.setFirstLetter(FirstLetterPingYin.FirstLetter(ryInventory.getName()));
        return ryInventoryMapper.updateRyInventory(ryInventory);
    }

    /**
     * 批量删除物品信息
     *
     * @param ids 需要删除的物品信息主键
     * @return 结果
     */
    @Override
    public int deleteRyInventoryByIds(Long[] ids)
    {
        return ryInventoryMapper.deleteRyInventoryByIds(ids);
    }

    /**
     * 删除物品信息信息
     *
     * @param id 物品信息主键
     * @return 结果
     */
    @Override
    public int deleteRyInventoryById(Long id)
    {
        return ryInventoryMapper.deleteRyInventoryById(id);
    }
}
